#include "SettingClass.h"
#include <QVBoxLayout>

SettingClass::SettingClass(QWidget *parent)
	: QDialog(parent)
{
	ui.setupUi(this);

	QVBoxLayout *layout = new QVBoxLayout();
	for (int i = 0; i < 50; i++)
	{
		SettingWidget *item = new SettingWidget();
		item->setNo(i + 1);
		m_settingItems << item;
		layout->addWidget(item);
	}	

	ui.scrollAreaWidgetContents->setLayout(layout);
}

SettingClass::~SettingClass()
{
}

void SettingClass::showEvent(QShowEvent *event)
{
	QDialog::showEvent(event);

	for (int i = 0; i < m_settingItems.size(); i++)
	{
		m_settingItems[i]->setEnable(setting.ipList[i].enable);
		m_settingItems[i]->setName(setting.ipList[i].name);
		m_settingItems[i]->setIp(setting.ipList[i].ip);
		m_settingItems[i]->setAddr(setting.ipList[i].addr);
		m_settingItems[i]->setDeviceType(setting.ipList[i].deviceType);
	}
}

void SettingClass::on_btnOk_clicked()
{
	for (int i = 0; i < m_settingItems.size(); i++)
	{
		setting.ipList[i].enable = m_settingItems[i]->enable();
		setting.ipList[i].name   = m_settingItems[i]->name();
		setting.ipList[i].ip   = m_settingItems[i]->ip();
		setting.ipList[i].addr = m_settingItems[i]->addr();
		setting.ipList[i].deviceType = m_settingItems[i]->deviceType();
	}
	accept();
}

void SettingClass::on_btnCancel_clicked()
{
	reject();
}